@namespace Oqtane.Modules.Admin.Dashboard
@inherits ModuleBase
@inject IPageService PageService
@inject IUserService UserService
@inject IStringLocalizer<SharedResources> SharedLocalizer

@if (_pages != null)
{
    <div class="row">
        @foreach (var p in _pages)
        {
            if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.PermissionList))
            {
                string url = NavigateUrl(p.Path);
                <p class="col-md-2 mx-auto text-center mb-3">
                    <NavLink class="nav-link text-primary" href="@url" Match="NavLinkMatch.All">
                        <h2><span class="@p.Icon" aria-hidden="true"></span></h2>
                        <p class="lead">@((MarkupString)SharedLocalizer[p.Name].ToString().Replace(" ", "<br />"))</p>
                    </NavLink>
                </p>
            }
        }
    </div>
}

@code {
	private List<Page> _pages;

    public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;

	protected override void OnInitialized()
	{
		var admin = PageState.Pages.FirstOrDefault(item => item.Path == "admin");
		if (admin != null)
		{
			_pages = PageState.Pages.Where(item => item.ParentId == admin.PageId).ToList();
		}
    }
}
